#include "Foundation.h"

Foundation::Foundation( FoundationType type )
{
    _type = type;
}

Foundation::~Foundation()
{
}

bool Foundation::insert(Card* card)
{
    Card* top = remove();
    insert(top);
    int nextValue = 0;
    int cardValue = card->getValue();
    int topValue = top->getValue();

    if( topValue == 13 )
    {
        return false;
    }

    switch (_type)
    {
        case SINGLE:
            nextValue = topValue+1;
            break;
        case DOUBLE:
            nextValue = topValue+2;
            break;
        case TRIPLE:
            nextValue = topValue+3;
            break;
        case QUADRUPLE:
            nextValue = topValue+4;
            break;
    }
    
    if( nextValue > 13)
    {
        nextValue -= 13;
    }
    
    if( nextValue == cardValue )
    {
        insert(card);
        return true;
    }
    return false;
}